<?php
/*
 * Created on Oct 30, 2013
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
?>


<style type="text/css">
<!--
    
    div.page {
        border: 1px solid #ddd9e9; 
    }
    
    /* title */
    div#title {
        color : #bd5741;
    }
    div#title > h3.title{
        margin-left: 2%;
    }
    
    /* profile */
    div.profile {
        padding: 10px;
        padding-top: 0px;
    }
    div.profile > p.title{
        color: #525252;
    }
    div#msg {
        width: 96%;
        margin-left:2%;
    }
-->
</style>

 <!-- navbar -->
    <table width="100%" cellspacing="0" cellpadding="0">
    <tbody>
    <tr>
    <td height="25px" align="left" class="header"> 
    <a title="Home" class="home" href="/">&nbsp;Home</a><span class="mark">&nbsp;&raquo;&nbsp;</span> <span class="home">Payment Setting</span> 
    </td>
    </tr>
    <tr>
    	<td colspan="1">&nbsp; </td>
    </tr>
    </tbody>
    </table>
    
<?=$menu?>


   
    
    <div class="page content_right">
        <div id="title">
            <h3 class="title">.::. Payment Setting</h3>
        </div>         

        <div id="msg">
        <?php if( isset($result) && $result == false): ?>
            <div class="error"> <span><?=$message?></span></div>
        <?php elseif (isset($result) && $result == true):?>
            <div class="success"><span><?=$message?></span></div>
        <?php endif; ?>
        </div>
<!-- payment account -->
        <form name="form_payment_account" method="POST" style="<?php
                if (isset($form_payment_account))
                {
                    //echo 'display:inline';
                }
                elseif (isset($form_new_payment_account))
                {
                    echo 'display:none';
                }
                else
                {
                    if (count($paymentAccounts)<=0)
                        echo 'display:none';
                }
                ?>
            ">                    
            <table class="pageContent" style="width:90%;margin-left:5%;" name="payment_account">
					<tbody>
                        <tr>
  			               <td id="heading" class="heading" colspan="2"><p>&nbsp;Billing Address &amp; Payment Account</p>
                            </td> 
   		               </tr>	
                        <tr>
				   		 	<td valign="top" class="notReq">Payment account:</td>
				   		 	<td>
                                <select onchange="change_payment_account(this)" name="paymentAccountId">  
                                    <?php if (isset($paymenttransactions)): ?>
                                    <?php foreach($paymenttransactions as $paymenttransaction){ ?>
                                        <option value="<?=$paymenttransaction->id?>">xxxx-xxxx-xxxx-<?=$paymenttransaction->cc_last4digits?></option>                                
                                    <?php } ?>                     
                                    <?php endif; ?> 
                                </select>
                                <span><a class="subbutton" style="position: static;" href="javascript:create_new_payment_account()">Create</a></span>
				   		 	</td>
			   		 	</tr>
						<tr>
							<td class="req"><div id="divbillAddress1"><span class="colortext">*</span>Address 1:</div></td>
							<td><input type="text" name="billAddress1" value="<?=isset($address)?$address->street_address_1:''?>" size="30" maxlength="255">                		 
			            	</td>
						</tr>
						<tr>
							<td class="notReq">Address 2:</td>
							<td><input type="text" name="billAddress2" value="<?=isset($address)?$address->street_address_2:''?>" size="30" maxlength="255"></td>
						</tr>
						<tr>
							<td class="req"><div id="divbillCountry"><span class="colortext">*</span>Country:</div></td>
							<td><select name="billCountry" id="billCountryId" onchange="change_country(this);" >
                                <?php foreach($countries as $country){
                                        if(isset($address) && $address->country == $country->id): ?>
                                            <option value="<?=$country->id?>" selected="true"><?=$country->name?></option>
                                    <?php else: ?>
                                            <option value="<?=$country->id?>"><?=$country->name?></option>                                
                                    <?php endif; 
                                    }
                                    ?>                                                                                                             
                                </select>
                                <input type="hidden" value="<?=(count($states)==0)?'no':'yes'?>" name="billHasState" />
                            </td>
						</tr>	
						<tr>
							<td class="req"><div id="divbillCity"><span class="colortext">*</span>City:</div></td>
							<td><input type="text" name="billCity" value="<?=isset($address)?$address->city:''?>" size="30" maxlength="255"></td>
						</tr>
						<tr>
							<td class="req"><div id="divbillState"><span class="colortext">*</span>State/Province:</div></td>
							<td>
                            <select name="billState" <?=(count($states)>0)?'':'style="display:none;"'?> >
                                <?php foreach($states as $state){?>  
                                    <?php if(isset($address) && $address->state == $state->id): ?>
                                            <option value="<?=$state->id?>" selected="true"><?=$state->name?></option>
                                    <?php else: ?>
                                            <option value="<?=$state->id?>"><?=$state->name?></option>                                
                                    <?php endif; ?> 
                                <?php } ?>
                            </select>
							<input type="text"  <?=(count($states)==0)?'':'style="display:none;"'?> name="billStateText" value="<?=isset($address)?$address->state:''?>" id="billStateTextId" maxlength="255" />                           
                             </td>
						</tr>	
						<tr>
							<td class="req"><div id="divbillZip"><span class="colortext">*</span>Zip:</div></td>
							<td><input type="text" name="billZip" value="<?=isset($address)?$address->zip_code:''?>" size="9" maxlength="9"></td>
						</tr>	
						<tr>
							<td class="req"><div id="divbillPhone"><span class="colortext">*</span>Phone:</div></td>
							<td>(<input type="text" name="billPhone1" value="<?=isset($address)?$address->area_code:''?>" size="3" maxlength="3" onkeypress="return validateKeyPressIsNumber(event);">)
                            <input type="text" name="billPhone2" value="<?=isset($address)?$address->phone_number:''?>" size="8" maxlength="8" onkeypress="return validateKeyPressIsPhone(event);"> 
                            &nbsp;Ext
                            <input type="text" name="billPhone3" value="<?=isset($address)?$address->phone_extension:''?>" size="5" maxlength="5" onkeypress="return validateKeyPressIsNumber(event);"></td>
						</tr>					
						<tr>
							<td colspan="2" class="spacer">&nbsp;</td>
						</tr>	
                        <tr>
                            <td></td>
                            <td class="buttonRow" colspan="2">
                                <input type="hidden" name="address_id" value="<?=isset($address)?$address->id:''?>" /> 
                                <input type="submit" name="submit" value="Update" class="button" />
                                <input type="reset" name="reset" value="Reset" class="button" />    
                            </td>
                        </tr>	
                        <tr>
						  <td class="spacer" colspan="2">&nbsp;</td>
						</tr>				
					</tbody>
				</table>
            </form>
<!-- Create new payment account -->
            <form name="form_new_payment_account" method="POST" style="<?php
                if (isset($form_payment_account))
                {
                    echo 'display:none';
                }
                elseif (isset($form_new_payment_account))
                {
                    
                }
                else
                {
                    if (count($paymentAccounts) > 0)
                    {
                        echo 'display:none';
                    }    
                }
                ?>
            ">       
    				<table style="width:90%;margin-left:5%;" class="pageContent">
    					<tbody>
                            <tr>
                                <td colspan="2" class="heading" id="heading"><p>&nbsp;Provider Billing Address &amp; Payment Account
                                </td> 
                            </tr>	
                                						
                            <tr>
    							<td class="req">Choose Card Type:</td>
    							<td>
                                <select style="height:18px;width:182px;" name="createPaymentCardType">
                                    <option value="Visa">Visa</option>
                                    <option value="Master Card">MasterCard</option>
                                    <option value="Discover">Discover</option>
                                    <option value="American Express">American Express</option>
                                </select>											
                                <span class="req"><img alt="cards" src="/images/cards.jpg" class="creditCardImage" /></span>
                                </td>
    						</tr>
    						
                            <tr>
    							<td class="req">Card Holder Name:</td>
    							<td><input type="text" maxlength="255" size="30" value="<?=isset($_POST['createPaymentName'])?$_POST['createPaymentName']:''?>" name="createPaymentName" /></td>
    						</tr>
    						
                            <tr>
    							<td class="req">Card Number:</td>
    							<td><input type="text" onblur="setCardTypeByNum(this.value, &quot;createPaymentCardType&quot;)" onkeypress="return validateKeyPressIsNumber(event);" maxlength="16" size="30" value="" name="createPaymentNumber"></td>
    						</tr>
    						   
    						<tr>
    							<td class="req">CVV Code:</td>
    							<td><input type="password" onkeypress="return validateKeyPressIsNumber(event);" maxlength="4" size="4" value="" name="createPaymentCVV2Code" /></td>
    						</tr>
    						
                            <tr>
    							<td class="req">Exp. Date</td>
    							<td>
    								<select style="height:18px;" name="createPaymentExpireMonth">
                                    <?php for ($i=1; $i<=12; $i++) echo "<option value='$i'>$i</option>" ?>
                                    </select>
                                    
    								<select style="height:18px;" name="createPaymentExpireYear">
                                        <?php $yearRange = 5; $thisYear = date('Y'); $startYear = ($thisYear + $yearRange);
                                           echo '<option value="'.$thisYear.'" selected="selected">' . $thisYear . '</option>';
                                           foreach (range($thisYear+1, $startYear) as $year) echo '<option value="'.$year.'">' . $year . '</option>'; ?>
                                    </select>							
                                    </td>
    						</tr>
    						
            <!-- ADDRESS -->
    						<tr>
    							<td colspan="2"><br /></td>
    						</tr>
    										
    						<tr>
    							<td class="req"><div><span class="colortext">*</span>Address 1:</div></td>
    							<td><input type="text" maxlength="255" size="30" value="<?=isset($_POST['createPaymentBillAddress1'])?$_POST['createPaymentBillAddress1']:''?>" name="createPaymentBillAddress1" />                		 
    			            	</td>
    						</tr>
    						<tr>
    							<td class="notReq">Address 2:</td>
    							<td><input type="text" maxlength="255" size="30" value="<?=isset($_POST['createPaymentBillAddress2'])?$_POST['createPaymentBillAddress2']:''?>" name="createPaymentBillAddress2" /></td>
    						</tr>
    						<tr>
    							<td class="req"><div id="divbillCountry"><span class="colortext">*</span>Country:</div></td>
    							<td><select onchange="change_country_2(this);" name="createPaymentBillCountry">
                                    <?php foreach($countries as $country){?>
                                    <option value="<?=$country->id?>"><?=$country->name?></option>                                
                                    <?php } ?>
                                </select>    
                                <input type="hidden" value="<?=(count($states)==0)?'no':'yes'?>" name="createPaymentHasState" />                        
                                </td>
    						</tr>	
    						<tr>
    							<td class="req"><div id="divbillCity"><span class="colortext">*</span>City:</div></td>
    							<td><input type="text" maxlength="255" size="30" value="<?=isset($_POST['createPaymentBillCity'])?$_POST['createPaymentBillCity']:''?>" name="createPaymentBillCity" /></td>
    						</tr>
    						<tr>
    							<td class="req"><div id="divbillState"><span class="colortext">*</span>State/Province:</div></td>
    							<td>
                                
                                <select name="createPaymentBillState" <?=(count($states)>0)?'':'style="display:none;"'?> >
                                <?php foreach($states as $state){?> <option value="<?=$state->id?>"><?=$state->name?></option> <?php } ?>
                                </select>
                                <input type="text" <?=(count($states)==0)?'':'style="display:none;"'?> size="15" maxlength="255" value="<?=isset($_POST['createPaymentBillStateText'])?$_POST['createPaymentBillStateText']:''?>" name="createPaymentBillStateText" /></td>
    						</tr>	
    						<tr>
    							<td class="req"><div id="divbillZip"><span class="colortext">*</span>Zip:</div></td>
    							<td><input type="text" maxlength="9" size="9" value="<?=isset($_POST['createPaymentBillZip'])?$_POST['createPaymentBillZip']:''?>" name="createPaymentBillZip" /></td>
    						</tr>	
    						<tr>
    							<td class="req"><div id="divbillPhone"><span class="colortext">*</span>Phone:</div></td>
    							<td>(<input type="text" onkeypress="return validateKeyPressIsNumber(event);" maxlength="3" size="3" value="<?=isset($_POST['createPaymentBillPhone1'])?$_POST['createPaymentBillPhone1']:''?>" name="createPaymentBillPhone1" />)
                                    <input type="text" onkeypress="return validateKeyPressIsPhone(event);" maxlength="8" size="8" value="<?=isset($_POST['createPaymentBillPhone2'])?$_POST['createPaymentBillPhone2']:''?>" name="createPaymentBillPhone2"/> 
                                    &nbsp;Ext
                                    <input type="text" onkeypress="return validateKeyPressIsNumber(event);" maxlength="5" size="5" value="<?=isset($_POST['createPaymentBillPhone3'])?$_POST['createPaymentBillPhone3']:''?>" name="createPaymentBillPhone3"/>
                                </td>
    						</tr>					
    						<tr>
    							<td class="spacer" colspan="2">&nbsp;</td>
    						</tr>				
                            <tr>
                                <td class="req">
                                    <?php if (count($paymentAccounts) > 0): ?>
                                    <span><a href="javascript:show_payment_account()" id="btnCreate" style="position: static;" class="subbutton">Back</a></span>
                                    <?php endif; ?>
                                </td>
                                <td> 
                                    <input type="submit" name="submit" value="Create" class="button" />
                                    <input type="reset" name="reset" value="Reset" class="button" /> 
                                </td>
                            </tr>
                            <tr>
    							<td class="spacer" colspan="2">&nbsp;</td>
    						</tr>
    					</tbody>
    				</table>
            </form>
        <div style="clear: both;"></div>
    </div>
</div>


<script type="text/javascript">
<!--
    function change_country(obj)
    {
        var country_id = obj.value;
        $.get( '/pay/ajax_getStatesByCountryId/' + country_id, function( content ) {
            if (content == '')
            {
                $('input[name=billHasState]').val('no');
                $('input[name=billStateText]').show();
                $('select[name=billState]').hide();
            }
            else
            {
                $('input[name=billHasState]').val('yes');
                $('input[name=billStateText]').hide();
                $('select[name=billState]').show();
                $('select[name=billState]').html(content);
            }
        });
    }
    function change_country_2(obj)
    {
        var country_id = obj.value;
        $.get( '/pay/ajax_getStatesByCountryId/' + country_id, function( content ) {
            if (content == '')
            {
                
                $('input[name=createPaymentBillState]').val('no');
                $('input[name=createPaymentBillStateText]').show();
                $('select[name=createPaymentBillState]').hide();
            }
            else
            {
                $('input[name=createPaymentBillState]').val('yes');
                $('input[name=createPaymentBillStateText]').hide();
                $('select[name=createPaymentBillState]').show();
                $('select[name=createPaymentBillState]').html(content);
            }
        });
    }
    function create_new_payment_account()
    {
        $('form[name=form_payment_account]').hide()
        $('form[name=form_new_payment_account]').show();
    }
     function show_payment_account()
    {
        $('form[name=form_payment_account]').show()
        $('form[name=form_new_payment_account]').hide();
    }
    function change_payment_account (obj)
    {
        $.get( '/pay/ajax_getAddress/' + obj.value, function( content ) {
            if (content.hasStates == 'yes')
            {
                var htmlStates = '';
                for (var i =0; i< content.states.length; i++)
                {
                    htmlStates += '<option value="'+content.states[i].id+'" >'+content.states[i].name+'</option>';
                }
                $('select[name=billState]').html(htmlStates);
                $('select[name=billState]').show();
                $('select[name=billState]').val(content.state);
                $('input[name=billStateText]').hide();
            }
            else
            {
                $('select[name=billState]').hide();
                $('input[name=billStateText]').show();
                $('input[name=billStateText]').val(content.state);
            }
            
            $('input[name=billAddress1]').val(content.street_address_1);
            $('input[name=billAddress2]').val(content.street_address_2);
            $('input[name=billCountry]').val(content.country);
            $('input[name=billCity]').val(content.city);
            $('input[name=billZip]').val(content.zip_code);
            $('input[name=billPhone1]').val(content.area_code);
            $('input[name=billPhone2]').val(content.phone_number);
            $('input[name=billPhone3]').val(content.phone_extension );
            $('input[name=address_id]').val(content.id);
        }, "json");
    }
  
-->
</script>